package com.jxit0573.android.lib.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;

/**
 * @author jia
 */
public class SignatureUtils {

    private SignatureUtils() {
    }

    public static String getMD5Signature(Context context) {
        Signature[] arrayOfSignature = getRawSignature(context, context.getPackageName());
        if (arrayOfSignature.length != 0) {
            StringBuilder sb = new StringBuilder();
            for (Signature sign : arrayOfSignature) {
                String s = StringUtils.getMessageDigest(sign.toByteArray());
                sb.append(s);
            }
            return sb.toString();
        } else {
            return null;
        }
    }

    private static Signature[] getRawSignature(Context context, String paramString) {
        if (paramString != null && paramString.length() != 0 && context != null) {
            PackageManager localPackageManager = context.getPackageManager();
            PackageInfo localPackageInfo;
            try {
                localPackageInfo = localPackageManager.getPackageInfo(paramString, PackageManager.GET_SIGNATURES);
                if (localPackageInfo == null) {
                    return null;
                }
            } catch (PackageManager.NameNotFoundException var5) {
                return null;
            }
            return localPackageInfo.signatures;
        } else {
            return null;
        }
    }
}
